package cc.cix.gt.org.service.impl;

import cc.cix.gt.common.entity.ResultPage;
import cc.cix.gt.common.util.SystemUtil;
import cc.cix.gt.org.dto.query.QueryDataPermissionTestReq;
import cc.cix.gt.org.entity.DataPermissionTest;
import cc.cix.gt.org.mapper.DataPermissionTestMapper;
import cc.cix.gt.org.service.IDataPermissionTestService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author cix
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class DataPermissionTestServiceImpl
        extends ServiceImpl<DataPermissionTestMapper, DataPermissionTest>
        implements IDataPermissionTestService {

    @Override
    public ResultPage<DataPermissionTest> listDataPermissionTest(
            QueryDataPermissionTestReq dto) {
        IPage<DataPermissionTest> objectPage =
                new Page<>(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<DataPermissionTest> lew =
                new LambdaQueryWrapper<DataPermissionTest>()
                        .orderByAsc(DataPermissionTest::getCreateTime);
        IPage<DataPermissionTest> dataPermissionTestPage = page(objectPage, lew);
        dataPermissionTestPage.setTotal(count(lew));
        return SystemUtil.getPage(dataPermissionTestPage);
    }
}
